
<template>
  <div id="big-data-container" class="big-data-container">
    <div class="head">
      <h1>联合重卡财务管理看板</h1>
    </div>
    <div class="data-container">
      <div class="data-left">
        <div class="data-left-item">
          <div class="title">
            科目费用分类统计（万元）
            <div class="top_right" style="display: flex">
              <el-select
                v-model="curr_yue"
                clearable
                placeholder="月份"
                @change="s_change"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                /> </el-select
              ><el-select
                v-model="rcntrlist_label"
                clearable
                placeholder="成本中心"
                @change="s_change"
              >
                <el-option
                  v-for="item in rcntrlist"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </div>
          <div id="chart-vleft-3" style="height: calc(100% - 55px)"></div>
          <div class="data-foot-line"></div>
        </div>
      </div>
      <div class="data-center">
        <!-- <div class="title">中间位置</div> -->
        <div class="center-top-num">
          <div class="item">
            <div class="text">今年预算总额（万元）</div>
            <div class="num">{{ total_ys }}</div>
          </div>
          <div class="item">
            <div class="text">今年费用实际发生总额（万元）</div>
            <div class="num">{{ total_sj }}</div>
          </div>

          <div class="data-foot-line"></div>
        </div>
        <div
          class="center-top"
          style="height: 260px; padding-top: 25px; overflow: hidden"
        >
          <!-- <div class="title">预算执行率</div> -->
          <div id="chart-vgauge-1" style="height: 330px"></div>
          <!-- <iview-circle :size="200" style="padding: 8px 0;"></iview-circle> -->
          <div class="data-foot-line"></div>
        </div>
        <div class="title">年度预算执行总览（万元）</div>
        <div id="chart-vcenter" style="height: 30%" class="chart-vcenter"></div>
        <div class="title">生产成本与主营收入对比（万元）</div>
        <div
          id="chart-vright-1"
          style="height: 25%"
          class="chart-vcenter"
        ></div>
      </div>
      <div class="data-right">
        <div class="data-right-item" style="height: 220px; padding-top: 25px">
          <div class="title">
            成本中心费用分类统计（万元）
            <div class="top_right" style="display: flex">
              <el-select
                v-model="curr_yue"
                clearable
                placeholder="分类选择"
                @change="s_change"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                /> </el-select
              ><el-select
                v-model="racctlist_label"
                clearable
                placeholder="科目"
                @change="s_change"
              >
                <el-option
                  v-for="item in racctlist"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </div>
          <div id="chart-vgauge-2" style="height: calc(100% - 55px)"></div>
          <div class="data-foot-line"></div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
var echarts = require("echarts");
let $chartLeft1,
  $chartLeft2,
  $chartLeft3,
  $chartCenter,
  $chartRight1,
  $chartGauge1,
  $chartGauge2;
import {
  chartLeft1,
  chartLeft2,
  chartLeft3,
  chartRight1,
  gauge,
} from "./bigdata/chart-options";
// import IviewCircle from "./bigdata/IviewCircle";
import "./bigdata/layout.less";
import http from "@/api/http.js";
export default {
  components: {
    // "iview-circle": IviewCircle
  },
  data() {
    return {
      rcntrlist: [],
      rcntrlist_label: "",
      racctlist: [],
      racctlist_label: "",
      total_ys: 0,
      total_sj: 0,
      curr_yue: 0,
      options: [
        {
          value: "1",
          label: "1月",
        },
        {
          value: "2",
          label: "2月",
        },
        {
          value: "3",
          label: "3月",
        },
        {
          value: "4",
          label: "4月",
        },
        {
          value: "5",
          label: "5月",
        },
        {
          value: "6",
          label: "6月",
        },
        {
          value: "7",
          label: "7月",
        },
        {
          value: "8",
          label: "8月",
        },
        {
          value: "9",
          label: "9月",
        },
        {
          value: "10",
          label: "10月",
        },
        {
          value: "11",
          label: "11月",
        },
        {
          value: "12",
          label: "12月",
        },
        {
          value: "0",
          label: "全年",
        },
      ],
    };
  },
  created() {
    //console.log("chart");
  },
  methods: {
    s_change() {
      //左边下拉改变
      var date = new Date();
      console.log(this.rcntrlist_label);
      console.log(this.racctlist_label);
      console.log(this.curr_yue);
      var nowMonth = date.getMonth() + 1;
      if (this.curr_yue > nowMonth) {
        this.$message.info(this.curr_yue + "月未发生费用");
        return;
      }
      this.get_left_1(this.curr_yue, this.rcntrlist_label); //科目分类统计
      this.get_right_1(this.curr_yue, this.racctlist_label);
    },
    get_left_1(yue, rcntr) {
      // this.init_get()
      let url = "/api/fkbigscreen/Km_f?yue=" + yue + "&rcntr=" + rcntr;
      //console.log(url);
      http.post(url, {}, true).then((s) => {
        console.log(s);
        //console.log(s.racct_list.racct);
        var mapy = new Array();
        var mapdata = new Array();
        s.racct_list.forEach((e) => {
          mapy.push(e.racct);
          mapdata.push((e.je / 10000).toFixed(2));
        });
        //let mapy=s.racct_list.map(s=>{return {s.racct}});
        //console.log(mapdata);
        $chartLeft3 = echarts.init(document.getElementById("chart-vleft-3")); //科目预算分类统计
        chartLeft3.yAxis.data.splice(0, chartLeft3.yAxis.data.length);
        chartLeft3.yAxis.data.push(...mapy);
        chartLeft3.series[0].data.splice(0, chartLeft3.series[0].data.length);
        chartLeft3.series[0].data.push(...mapdata);
        $chartLeft3.setOption(chartLeft3, true);
        //console.log(chartLeft3);
      });

      this.get_center();
      //
    },

    get_right_1(yue, racct) {
      http
        .post(
          "/api/fkbigscreen/Cntr_f?yue=" + yue + "&racct=" + racct,
          {},
          true
        )
        .then((s) => {
          var mapy = new Array();
          var mapdata = new Array();
          s.rcntr_list.forEach((e) => {
            mapy.push(e.rcntr);
            mapdata.push((e.je / 10000).toFixed(2));
          });

          $chartGauge2 = echarts.init(
            document.getElementById("chart-vgauge-2")
          );
          chartLeft1.yAxis.data.splice(0, chartLeft1.yAxis.data.length);
          chartLeft1.yAxis.data.push(...mapy);
          chartLeft1.series[0].data.splice(0, chartLeft1.series[0].data.length);
          chartLeft1.series[0].data.push(...mapdata);
          $chartGauge2.setOption(chartLeft1);
        });
      //  this.init_get();
      this.get_center();
    },
    get_center() {
      let url =
        "/api/fkbigscreen/get_kanb?racct=" +
        this.racctlist_label +
        "&rcntr=" +
        this.rcntrlist_label;
      http.post(url, {}, true).then((s) => {
        chartRight1.series[0].data.splice(0, chartRight1.series[0].data.length);
        chartRight1.series[0].data.push(...s.sum_yu_list);
        chartRight1.series[1].data.splice(0, chartRight1.series[1].data.length);
        chartRight1.series[1].data.push(...s.sum_sj_list);
        $chartCenter = echarts.init(document.getElementById("chart-vcenter")); //年度预算执行总览
        $chartCenter.setOption(chartRight1, true);
      });
    },
    init_get() {
      this.rcntrlist_label = "all";
      this.racctlist_label = "all";
      let url =
        "/api/fkbigscreen/get_kanb?racct=" +
        this.racctlist_label +
        "&rcntr=" +
        this.rcntrlist_label;
      http.post(url, {}, true).then((s) => {
        this.total_ys = s.sum_yuan;
        this.total_sj = s.sum_sj;
        //console.log(s);
        gauge.series[0].data[0].value = this.total_sj / this.total_ys;
        $chartGauge1 = echarts.init(document.getElementById("chart-vgauge-1")); //中间的仪表盘，预算执行率
        $chartGauge1.setOption(gauge, true);

        chartRight1.series[0].data.splice(0, chartRight1.series[0].data.length);
        chartRight1.series[0].data.push(...s.sum_yu_list);
        chartRight1.series[1].data.splice(0, chartRight1.series[1].data.length);
        chartRight1.series[1].data.push(...s.sum_sj_list);
        $chartCenter = echarts.init(document.getElementById("chart-vcenter")); //年度预算执行总览
        $chartCenter.setOption(chartRight1, true);

        chartLeft2.series[0].data.splice(0, chartLeft2.series[0].data.length);
        chartLeft2.series[0].data.push(...s.yue_cenb); //9000生产成本
        chartLeft2.series[1].data.splice(0, chartLeft2.series[1].data.length);
        chartLeft2.series[1].data.push(...s.yue_shour); //8000主营业务收入
        $chartRight1 = echarts.init(document.getElementById("chart-vright-1")); //应收账款走势
        $chartRight1.setOption(chartLeft2, true);
        //console.log(s)

        this.rcntrlist = s.array_rcntrlist;
        this.rcntrlist.splice(0, 0, {
          value: "all",
          label: "【全部成本中心】",
        }); //插入到第0位

        this.rcntrlist.push({ value: "all", label: "【全部成本中心】" });

        this.racctlist = s.array_racctlist;
        this.racctlist.splice(0, 0, { value: "all", label: "【全部科目】" }); //插入到第0位

        this.racctlist.push({ value: "all", label: "【全部科目】" });

        //var date = new Date();
        var Last_month = new Date().getMonth();
        Last_month = Last_month == 0 ? 12 : Last_month; //获取上月的月份
        //var nowMonth = date.getMonth() + 1;
        this.curr_yue = Last_month; // "全年/0"
        this.get_left_1(Last_month, this.rcntrlist_label); //科目分类统计
        this.get_right_1(Last_month, this.racctlist_label); //成本中心分类统计
      });
    },
  },
  mounted() {
    this.init_get();

    if ($chartLeft1) {
      $chartLeft1.dispose();
      $chartLeft2.dispose();
      $chartLeft3.dispose();
      $chartCenter.dispose();
      $chartRight1.dispose();
      $chartGauge1.dispose();
      $chartGauge2.dispose();
    }
    /* $chartLeft1 = echarts.init(document.getElementById("chart-vleft-1"));
    $chartLeft1.setOption(chartLeft1, true); */

    /*  $chartLeft2 = echarts.init(document.getElementById("chart-vleft-2"));
    $chartLeft2.setOption(chartLeft2, true); */

    /*   $chartGauge2 = echarts.init(document.getElementById("chart-vgauge-2"));
    $chartGauge2.setOption(gauge); */
  },
  destroyed() {
    $chartLeft1 = null;
    $chartLeft2 = null;
    $chartLeft3 = null;
    $chartCenter = null;
    $chartRight1 = null;
    $chartGauge1 = null;
    $chartGauge2 = null;
  },
};
</script>
<style  scoped>
/* .chart-center {
  display: flex;
  border: 1px solid #0000ff;
  height: 200px;
  flex-direction: column;
  margin-top: 20px;
}
.chart-center .item {
  text-align: center;
  border: 1px solid #00c1b3;
  flex: 1;
} */
.right-3 {
  display: flex;
  flex-direction: column;
  /* margin-top: 20px; */
}

.right-3 .right-item {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.right-3 .item {
  text-align: left;
  border-bottom: 1px solid #549069;
  flex: 1;
  display: flex;
  padding: 5px 10px;
  margin: 0 10px;
  font-size: 14px;
  line-height: 30px;
}

.right-3 .item:last-child {
  border-bottom: 0;
}

.right-3 .item > div {
  color: white;
}

.right-3 .top {
  width: 60px;
  position: relative;
}

.right-3 .top span {
  position: absolute;
  width: 20px;
  line-height: 20px;
  top: 5px;
  text-align: center;
  border-radius: 5px;
}

.right-3 .top-1 span {
  background: #e80d0d;
}

.right-3 .top-2 span {
  background: #00c935;
}

.right-3 .top-3 span {
  background: #0083f4;
}

.right-3 .num {
  width: 88px;
}

.right-3 .pro-name {
  flex: 1;
}
.top_right {
  width: 300px;
  margin-left: auto;
  text-align: right;
}
::v-deep .el-select,
::v-deep .el-input,
::v-deep .el-input__inner {
  background-color: #031352;
  color: #fff;
  border: 0px;
  border-radius: 0px;
  text-align: center;
}
</style>




